package br.ufrgs.ga.operators;

import java.security.InvalidParameterException;

/**
 * Genetic mutation operator implementation.
 * @author mineiro
 *
 */
public class MutationOperator implements IMutation<String> {
	
	/**
	 * Implements a simple genetic mutation operation.<br>
	 * This implementation swaps the char at i + 1 with the char at i in the DNA strand string.
	 */
	@Override
	public String execute(String dnaStrand) {
		if (dnaStrand == null || dnaStrand.isEmpty()) {
			throw new InvalidParameterException("The DNA strand cannot be null or an empty string.");
		}
		
		String newDnaStrand = "";
		for(int i = 0; i < dnaStrand.length() - 1; i += 2) {
			newDnaStrand += dnaStrand.substring(i + 1, i + 2);
			newDnaStrand += dnaStrand.substring(i, i + 1);
		}
		
		return newDnaStrand;
	}

	
}